import {ConfigBase, IElementBase} from "./ConfigBase";
import {CanPickupMoneyConfig} from "./CanPickupMoney";
import {CheckpointConfig} from "./Checkpoint";
import {GrowConfig} from "./Grow";
import {GrowTypeConfig} from "./GrowType";
import {LevelConfig} from "./Level";

export class GameConfig{
	private static configMap:Map<string, ConfigBase<IElementBase>> = new Map();
	/**
	* 多语言设置
	* @param languageIndex 语言索引(-1为系统默认语言)
	* @param getLanguageFun 根据key获取语言内容的方法
	*/
	public static initLanguage(languageIndex:number, getLanguageFun:(key:string|number)=>string){
		ConfigBase.initLanguage(languageIndex, getLanguageFun);
		this.configMap.clear();
	}
	public static getConfig<T extends ConfigBase<IElementBase>>(ConfigClass: { new(): T }): T {
		if (!this.configMap.has(ConfigClass.name)) {
			this.configMap.set(ConfigClass.name, new ConfigClass());
		}
		return this.configMap.get(ConfigClass.name) as T;
	}
	public static get CanPickupMoney():CanPickupMoneyConfig{ return this.getConfig(CanPickupMoneyConfig) };
	public static get Checkpoint():CheckpointConfig{ return this.getConfig(CheckpointConfig) };
	public static get Grow():GrowConfig{ return this.getConfig(GrowConfig) };
	public static get GrowType():GrowTypeConfig{ return this.getConfig(GrowTypeConfig) };
	public static get Level():LevelConfig{ return this.getConfig(LevelConfig) };
}